#include "Shape.h"


Shape::Shape(vec4 _pos, vec3 _rot){
	pos = _pos;
	rot = _rot;
	sc = 1.0f;
	modelviewMat = mat4();
	invModelviewMat = mat4();
	updateModelViewMat();
	shade = NULL;
}


Shape::~Shape(){
}

ShaderCollection* Shape::shader(){
	return shade;
}
void Shape::shader(ShaderCollection* _shader){
	shade = _shader;
}

vec4 Shape::position(){ 
	return pos;
}
void Shape::position(vec4 _pos){ 
	pos = _pos;
	//update the transform matrix
	updateModelViewMat();
}

vec3 Shape::rotation(){ 
	return rot; 
}
void Shape::rotation(vec3 _rot){ 
	rot = _rot; 
	//update the transform matrix
	updateModelViewMat();
}

float Shape::scale(){
	return sc;
}
void Shape::scale(float _scale){
	sc = _scale;
}

void Shape::updateModelViewMat(){
	modelviewMat = mat4();
	
	modelviewMat = rotate(modelviewMat, rot.z, vec3(0, 0, 1));
	modelviewMat = rotate(modelviewMat, rot.x, vec3(1, 0, 0));
	modelviewMat = rotate(modelviewMat, rot.y, vec3(0, 1, 0));
	modelviewMat = translate(modelviewMat, -vec3(pos));

	invModelviewMat = mat4();
	invModelviewMat = translate(invModelviewMat, vec3(pos));
	invModelviewMat = rotate(invModelviewMat, -rot.y, vec3(0, 1, 0));
	invModelviewMat = rotate(invModelviewMat, -rot.x, vec3(1, 0, 0));
	invModelviewMat = rotate(invModelviewMat, -rot.z, vec3(0, 0, 1));
	
}